module ram_burst_len_caculator (
    // APB
    input wire [1:0] matrix_type,  // 00:m32n8k16, 01:m16n16k16, 10:m8n32k16
    input wire [1:0] data_type,    // 00:INT4, 01:INT8, 10:FP16, 11:FP32
    // ram_len
    output reg [7:0] matrix_c_transfers, // ram0
    output reg [7:0] matrix_b_transfers, // ram1
    output reg [7:0] matrix_a_transfers  // ram2
);
    
    // 根据矩阵类型和数据类型计算各矩阵的传输次数
        always @(*) begin
            case ({matrix_type, data_type})
                // m32n8k16矩阵类型
                4'b0000: begin  // INT4
                    matrix_c_transfers = 8'd8;   // C: 256÷32=8
                    matrix_b_transfers = 8'd4;   // B: 128÷32=4
                    matrix_a_transfers = 8'd16;  // A: 512÷32=16
                end
                4'b0001: begin  // INT8
                    matrix_c_transfers = 8'd16;  // C: 256÷16=16
                    matrix_b_transfers = 8'd8;   // B: 128÷16=8
                    matrix_a_transfers = 8'd32;  // A: 512÷16=32
                end
                4'b0010: begin  // FP16
                    matrix_c_transfers = 8'd32;  // C: 256÷8=32
                    matrix_b_transfers = 8'd16;  // B: 128÷8=16
                    matrix_a_transfers = 8'd64;  // A: 512÷8=64
                end
                4'b0011: begin  // FP32
                    matrix_c_transfers = 8'd64;  // C: 256÷4=64
                    matrix_b_transfers = 8'd32;  // B: 128÷4=32
                    matrix_a_transfers = 8'd128; // A: 512÷4=128
                end
                
                // m16n16k16矩阵类型 (所有矩阵都是256个元素)
                4'b0100: begin  // INT4
                    matrix_c_transfers = 8'd8;   // 256÷32=8
                    matrix_b_transfers = 8'd8;
                    matrix_a_transfers = 8'd8;
                end
                4'b0101: begin  // INT8
                    matrix_c_transfers = 8'd16;  // 256÷16=16
                    matrix_b_transfers = 8'd16;
                    matrix_a_transfers = 8'd16;
                end
                4'b0110: begin  // FP16
                    matrix_c_transfers = 8'd32;  // 256÷8=32
                    matrix_b_transfers = 8'd32;
                    matrix_a_transfers = 8'd32;
                end
                4'b0111: begin  // FP32
                    matrix_c_transfers = 8'd64;  // 256÷4=64
                    matrix_b_transfers = 8'd64;
                    matrix_a_transfers = 8'd64;
                end
                
                // m8n32k16矩阵类型
                4'b1000: begin  // INT4
                    matrix_c_transfers = 8'd8;   // C: 256÷32=8
                    matrix_b_transfers = 8'd16;  // B: 512÷32=16
                    matrix_a_transfers = 8'd4;   // A: 128÷32=4
                end
                4'b1001: begin  // INT8
                    matrix_c_transfers = 8'd16;  // C: 256÷16=16
                    matrix_b_transfers = 8'd32;  // B: 512÷16=32
                    matrix_a_transfers = 8'd8;   // A: 128÷16=8
                end
                4'b1010: begin  // FP16
                    matrix_c_transfers = 8'd32;  // C: 256÷8=32
                    matrix_b_transfers = 8'd64;  // B: 512÷8=64
                    matrix_a_transfers = 8'd16;  // A: 128÷8=16
                end
                4'b1011: begin  // FP32
                    matrix_c_transfers = 8'd64;  // C: 256÷4=64
                    matrix_b_transfers = 8'd128; // B: 512÷4=128
                    matrix_a_transfers = 8'd32;  // A: 128÷4=32
                end
                
                default: begin
                    matrix_c_transfers = 8'd0;
                    matrix_b_transfers = 8'd0;
                    matrix_a_transfers = 8'd0;
                end
            endcase
        end
    
endmodule